<?php

/**
 * Description of default
 *
 * @author Montana
 */
class Defaults extends CI_Controller {

    function index(){
       if(!$this->session->userdata('user_name')){
           redirect("/defaults/loginPage");
       }else {
           redirect("/testing");
       }
    }

    /**
     * Render login page
     */
    function loginPage(){
        $this->template->setPage('pages/login_box');
    }

    function doLogin(){
        if(strlen($this->input->post('user_name')) < 3){
            echo json_encode(array('error' => 'User name must be greater than 3 symbols'));
            exit;
        }
        $sesData['user_id']   = rand();
        $sesData['user_name'] = $this->input->post('user_name');
        
        $this->session->set_userdata($sesData);

        echo json_encode(array('url' => base_url()."index.php/testing/"));
        exit;
    }
    
}
?>
